import csv
data=[{
	'hostname':'sw1',
	'location':'Beijing,Xicheng',
	'model':'5700',
	'vendor':'Huawei'
},{
	'hostname':'sw2',
	'location':'Shanghai',
	'model':'3700',
	'vendor':'Huawei'
}]

csv_path=r'c:\tools\csv-lab1-wrting1.csv'

with open(csv_path,'w',newline='') as f:
	writer=csv.DictWriter(
		f,fieldnames=list(data[0].keys()),quoting=csv.QUOTE_NONNUMERIC)
	writer.writeheader()
	for d in data:
		writer.writerow(d)


with open(csv_path) as f:
	print(f.read())